import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
const router = new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: () => import('@/components/index.vue')
    },
    {
      path: '/index',
      redirect: '/'
    },
    {
      path: '/result',
      name: 'result',
      component: () => import('@/components/result.vue')
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.name === 'result' && typeof window.$searchParams !== 'object') {
    next({
      path: '/index'
    });
  } else {
    next();
  }
})
export default router
